<div class="container">
  <h1 id="pkg-overview">package constant</h1>

        <p><code>import "go/constant"</code>

        </p><p>
Package constant implements Values representing untyped
Go constants and their corresponding operations.
</p>
<p>
A special Unknown value may be used when a value
is unknown due to an error. Operations on unknown
values produce unknown values unless specified
otherwise.</p>


        
  


        
        

        

        

        
        
          
        

        
        


<p><a href="https://github.com/golang/go/blob/master/src/go/constant/value.go">value.go</a> </p>

        
        

        
        

        
        
        
          <h2 data-kind="f" id="BitLen">func <a href="https://github.com/golang/go/blob/master/src/go/constant/value.go#L473" title="View Source">BitLen</a>  </h2>
          <p>
BitLen returns the number of bits required to represent
the absolute value x in binary representation; x must be an Int or an Unknown.
If x is Unknown, the result is 0.
</p>

          
  

        
          <h2 data-kind="f" id="BoolVal">func <a href="https://github.com/golang/go/blob/master/src/go/constant/value.go#L368" title="View Source">BoolVal</a>  </h2>
          <p>
BoolVal returns the Go boolean value of x, which must be a Bool or an Unknown.
If x is Unknown, the result is false.
</p>

          
  

        
          <h2 data-kind="f" id="Bytes">func <a href="https://github.com/golang/go/blob/master/src/go/constant/value.go#L526" title="View Source">Bytes</a>  </h2>
          <p>
Bytes returns the bytes for the absolute value of x in little-
endian binary representation; x must be an Int.
</p>

          
  

        
          <h2 data-kind="f" id="Compare">func <a href="https://github.com/golang/go/blob/master/src/go/constant/value.go#L1184" title="View Source">Compare</a>  </h2>
          <p>
Compare returns the result of the comparison x op y.
The comparison must be defined for the operands.
If one of the operands is Unknown, the result is
false.
</p>

          
  

        
          <h2 data-kind="f" id="Float32Val">func <a href="https://github.com/golang/go/blob/master/src/go/constant/value.go#L425" title="View Source">Float32Val</a>  </h2>
          <p>
Float32Val is like Float64Val but for float32 instead of float64.
</p>

          
  

        
          <h2 data-kind="f" id="Float64Val">func <a href="https://github.com/golang/go/blob/master/src/go/constant/value.go#L450" title="View Source">Float64Val</a>  </h2>
          <p>
Float64Val returns the nearest Go float64 value of x and whether the result is exact;
x must be numeric or an Unknown, but not Complex. For values too small (too close to 0)
to represent as float64, Float64Val silently underflows to 0. The result sign always
matches the sign of x, even for 0.
If x is Unknown, the result is (0, false).
</p>

          
  

        
          <h2 data-kind="f" id="Int64Val">func <a href="https://github.com/golang/go/blob/master/src/go/constant/value.go#L395" title="View Source">Int64Val</a>  </h2>
          <p>
Int64Val returns the Go int64 value of x and whether the result is exact;
x must be an Int or an Unknown. If the result is not exact, its value is undefined.
If x is Unknown, the result is (0, false).
</p>

          
  

        
          <h2 data-kind="f" id="Sign">func <a href="https://github.com/golang/go/blob/master/src/go/constant/value.go#L489" title="View Source">Sign</a>  </h2>
          <p>
Sign returns -1, 0, or 1 depending on whether x &lt; 0, x == 0, or x &gt; 0;
x must be numeric or Unknown. For complex values x, the sign is 0 if x == 0,
otherwise it is != 0. If x is Unknown, the result is 1.
</p>

          
  

        
          <h2 data-kind="f" id="StringVal">func <a href="https://github.com/golang/go/blob/master/src/go/constant/value.go#L381" title="View Source">StringVal</a>  </h2>
          <p>
StringVal returns the Go string value of x, which must be a String or an Unknown.
If x is Unknown, the result is "".
</p>

          
  

        
          <h2 data-kind="f" id="Uint64Val">func <a href="https://github.com/golang/go/blob/master/src/go/constant/value.go#L411" title="View Source">Uint64Val</a>  </h2>
          <p>
Uint64Val returns the Go uint64 value of x and whether the result is exact;
x must be an Int or an Unknown. If the result is not exact, its value is undefined.
If x is Unknown, the result is (0, false).
</p>

          
  

        

        
        

        
          <h2 data-kind="t" id="Kind">type <a href="https://github.com/golang/go/blob/master/src/go/constant/value.go#L25" title="View Source">Kind</a>  </h2>
          <p>
Kind specifies the kind of value represented by a Value.
</p>

          
          
          
  


          

          
        
          <h2 data-kind="t" id="Value">type <a href="https://github.com/golang/go/blob/master/src/go/constant/value.go#L42" title="View Source">Value</a>  </h2>
          <p>
A Value represents the value of a Go constant.
</p>

          
          
          
  


          
            <h3 data-kind="f" id="BinaryOp">func <a href="https://github.com/golang/go/blob/master/src/go/constant/value.go#L948" title="View Source">BinaryOp</a>  </h3>
            <p>
BinaryOp returns the result of the binary expression x op y.
The operation must be defined for the operands. If one of the
operands is Unknown, the result is Unknown.
BinaryOp doesn't handle comparisons or shifts; use Compare
or Shift instead.
</p>
<p>
To force integer division of Int operands, use op == token.QUO_ASSIGN
instead of token.QUO; the result is guaranteed to be Int in this case.
Division by zero leads to a run-time panic.
</p>

            
  

          
            <h3 data-kind="f" id="Denom">func <a href="https://github.com/golang/go/blob/master/src/go/constant/value.go#L612" title="View Source">Denom</a>  </h3>
            <p>
Denom returns the denominator of x; x must be Int, Float, or Unknown.
If x is Unknown, or if it is too large or small to represent as a
fraction, the result is Unknown. Otherwise the result is an Int &gt;= 1.
</p>

            
  

          
            <h3 data-kind="f" id="Imag">func <a href="https://github.com/golang/go/blob/master/src/go/constant/value.go#L660" title="View Source">Imag</a>  </h3>
            <p>
Imag returns the imaginary part of x, which must be a numeric or unknown value.
If x is Unknown, the result is Unknown.
</p>

            
  

          
            <h3 data-kind="f" id="MakeBool">func <a href="https://github.com/golang/go/blob/master/src/go/constant/value.go#L281" title="View Source">MakeBool</a>  </h3>
            <p>
MakeBool returns the Bool value for b.
</p>

            
  

          
            <h3 data-kind="f" id="MakeFloat64">func <a href="https://github.com/golang/go/blob/master/src/go/constant/value.go#L299" title="View Source">MakeFloat64</a>  </h3>
            <p>
MakeFloat64 returns the Float value for x.
If x is not finite, the result is an Unknown.
</p>

            
  

          
            <h3 data-kind="f" id="MakeFromBytes">func <a href="https://github.com/golang/go/blob/master/src/go/constant/value.go#L558" title="View Source">MakeFromBytes</a>  </h3>
            <p>
MakeFromBytes returns the Int value given the bytes of its little-endian
binary representation. An empty byte slice argument represents 0.
</p>

            
  

          
            <h3 data-kind="f" id="MakeFromLiteral">func <a href="https://github.com/golang/go/blob/master/src/go/constant/value.go#L315" title="View Source">MakeFromLiteral</a>  </h3>
            <p>
MakeFromLiteral returns the corresponding integer, floating-point,
imaginary, character, or string value for a Go literal string. The
tok value must be one of token.INT, token.FLOAT, token.IMAG,
token.CHAR, or token.STRING. The final argument must be zero.
If the literal string syntax is invalid, the result is an Unknown.
</p>

            
  

          
            <h3 data-kind="f" id="MakeImag">func <a href="https://github.com/golang/go/blob/master/src/go/constant/value.go#L634" title="View Source">MakeImag</a>  </h3>
            <p>
MakeImag returns the Complex value x*i;
x must be Int, Float, or Unknown.
If x is Unknown, the result is Unknown.
</p>

            
  

          
            <h3 data-kind="f" id="MakeInt64">func <a href="https://github.com/golang/go/blob/master/src/go/constant/value.go#L287" title="View Source">MakeInt64</a>  </h3>
            <p>
MakeInt64 returns the Int value for x.
</p>

            
  

          
            <h3 data-kind="f" id="MakeString">func <a href="https://github.com/golang/go/blob/master/src/go/constant/value.go#L284" title="View Source">MakeString</a>  </h3>
            <p>
MakeString returns the String value for s.
</p>

            
  

          
            <h3 data-kind="f" id="MakeUint64">func <a href="https://github.com/golang/go/blob/master/src/go/constant/value.go#L290" title="View Source">MakeUint64</a>  </h3>
            <p>
MakeUint64 returns the Int value for x.
</p>

            
  

          
            <h3 data-kind="f" id="MakeUnknown">func <a href="https://github.com/golang/go/blob/master/src/go/constant/value.go#L278" title="View Source">MakeUnknown</a>  </h3>
            <p>
MakeUnknown returns the Unknown value.
</p>

            
  

          
            <h3 data-kind="f" id="Num">func <a href="https://github.com/golang/go/blob/master/src/go/constant/value.go#L590" title="View Source">Num</a>  </h3>
            <p>
Num returns the numerator of x; x must be Int, Float, or Unknown.
If x is Unknown, or if it is too large or small to represent as a
fraction, the result is Unknown. Otherwise the result is an Int
with the same sign as x.
</p>

            
  

          
            <h3 data-kind="f" id="Real">func <a href="https://github.com/golang/go/blob/master/src/go/constant/value.go#L647" title="View Source">Real</a>  </h3>
            <p>
Real returns the real part of x, which must be a numeric or unknown value.
If x is Unknown, the result is Unknown.
</p>

            
  

          
            <h3 data-kind="f" id="Shift">func <a href="https://github.com/golang/go/blob/master/src/go/constant/value.go#L1128" title="View Source">Shift</a>  </h3>
            <p>
Shift returns the result of the shift expression x op s
with op == token.SHL or token.SHR (&lt;&lt; or &gt;&gt;). x must be
an Int or an Unknown. If x is Unknown, the result is x.
</p>

            
  

          
            <h3 data-kind="f" id="ToComplex">func <a href="https://github.com/golang/go/blob/master/src/go/constant/value.go#L751" title="View Source">ToComplex</a>  </h3>
            <p>
ToComplex converts x to a Complex value if x is representable as a Complex.
Otherwise it returns an Unknown.
</p>

            
  

          
            <h3 data-kind="f" id="ToFloat">func <a href="https://github.com/golang/go/blob/master/src/go/constant/value.go#L732" title="View Source">ToFloat</a>  </h3>
            <p>
ToFloat converts x to a Float value if x is representable as a Float.
Otherwise it returns an Unknown.
</p>

            
  

          
            <h3 data-kind="f" id="ToInt">func <a href="https://github.com/golang/go/blob/master/src/go/constant/value.go#L678" title="View Source">ToInt</a>  </h3>
            <p>
ToInt converts x to an Int value if x is representable as an Int.
Otherwise it returns an Unknown.
</p>

            
  

          
            <h3 data-kind="f" id="UnaryOp">func <a href="https://github.com/golang/go/blob/master/src/go/constant/value.go#L787" title="View Source">UnaryOp</a>  </h3>
            <p>
UnaryOp returns the result of the unary expression op y.
The operation must be defined for the operand.
If prec &gt; 0 it specifies the ^ (xor) result size in bits.
If y is Unknown, the result is Unknown.
</p>

<div class="clearfix" id="x-footer">
  <div class="container">
    <a href="http://studygolang.com/" target="_blank">Go语言中文网</a>
    <span class="text-muted">|</span> <a href="http://golang.org/" target="_blank">Go Language</a>
    <span class="pull-right"><a href="#">Back to top</a></span>
  </div>
</div>
<script src="../assets/jquery-2.0.3.min.js"></script>
<script src="../assets/bootstrap.min.js"></script>
<script src="../assets/site.js"></script>


</div>